package j20251127;

import java.util.PriorityQueue;

public class Solution1 {
    public int lastStoneWeight(int[] stones) {
        PriorityQueue<Integer> heap = new PriorityQueue<>((a, b)->b-a);
        for(int x:stones){
            heap.offer(x);
        }
        while(heap.size()>1){
            int num1=heap.poll();
            int num2=heap.poll();
            if(num1>num2){
                heap.offer(num1-num2);
            }
        }
        return heap.isEmpty()?0:heap.peek();
    }
}
